import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_app/BaseMaterialStateWidget.dart';

class LoadingPage extends BaseMaterialStateWidget {
  var _remain = 5;
  var _timer;

  @override
  void initState(BuildContext context) {
    super.initState(context);
    _timer = Timer.periodic(Duration(seconds: 1), (timer) {
      if (_remain < 1) {
        Navigator.of(context).pushReplacementNamed("home");
        _timer.cancel();
      } else {
        setState(() {
          _remain = _remain - 1;
        });
      }
    });
  }

  @override
  Widget buildContent(BuildContext context) {
    return Center(
      child: Text('倒计时${_remain}s'),
    );
  }

  @override
  String getTitle() {
    return null;
  }

  @override
  void dispose() {
    super.dispose();
    if (_timer != null) {
      _timer.cancel();
    }
  }
}
